1 /*
  2 * Copyright (c) 2014 Nonki Takahashi. All rights reserved.
  3 *
  4 * History:
  5 *  0.1 2014-01-17 Created.
  6 */
  7 
  8 /**
  9  * @fileOverview Unit Test Specification for EBNF Parser Generator Object
 10  * @version 0.1
 11  * @author Nonki Takahashi
 12  */
 13 
 14 describe("Generator 仕様 0.1", function() {
 15   var g = new EBNFParser("syntax = {line, nl}.", "Test", "0.1");
 16   var code = "/**\n";
 17   code += " * @fileOverview TestParser - Test Parser Object\n";
 18   code += " * @version 0.1\n";
 19   code += " * @author EBNFParser written by Nonki Takahashi\n";
 20   code += " */\n";
 21   code += "\n";
 22   code += "/**\n";
 23   code += " * Test Parser Generator Object\n";
 24   code += " * @this {TestParser}\n";
 25   code += " * @param {String} syntax syntax object for generate parser\n";
 26   code += " * @param {String} name name of the parser\n";
 27   code += " * @param {String} ver version of the parser\n";
 28   code += " * @property {String} buf syntax buffer\n";
 29   code += " * @property {Integer} ptr syntax buffer pointer\n";
 30   code += " * @property {String} name name of the parser\n";
 31   code += " * @property {String} ver version of the parser\n";
 32   code += " * @since 0.1\n";
 33   code += " */\n";
 34   code += "TestParser = function(syntax, name, ver) {\n";
 35   code += "this.name = name;\n";
 36   code += "this.ver = ver;\n";
 37   code += "// inherit the methods of class Lex\n";
 38   code += "Lex.call(this, syntax);\n";
 39   code += "};\n";
 40   code += "TestParser.prototype = new Lex();\n";
 41   code += "\n";
 42   code += "/**\n";
 43   code += " * syntax\n";
 44   code += " * @returns {String} code generated if matched, null if not matched\n";
 45   code += " * @since 0.1\n";
 46   code += " */\n";
 47   code += "TestParser.prototype.syntax = function() {\n";
 48   code += "var match = [];\n";
 49   code += "var save = this.ptr;\n";
 50   code += "var n = -1;\n";
 51   code += "while(match[n]) {\n";
 52   code += "match[++n] = this.line();\n";
 53   code += "if (match[n]) {\n";
 54   code += "match[++n] = this.nl();\n";
 55   code += "}\n";
 56   code += "}\n";
 57   code += "match[++n] = true;\n";
 58   code += "if (!match[n]) {\n";
 59   code += "this.ptr = save;\n";
 60   code += "return null;\n";
 61   code += "}\n";
 62   code += "return this.run(n, match, \"syntax\");\n";
 63   code += "};\n\n";
 64 
 65   it("syntax() は " + code + " を返す", function() {
 66     expect(g.syntax()).toEqual(code);
 67   });
 68 
 69 });
 70